home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / RTF / space.h < prev    next >
C/C++ Source or Header  |  1994-08-01  |  4KB  |  165 lines

  1. /* $Header: /usr/people/pcd/Src/RTF/RCS/space.h,v 1.1 92/11/23 12:58:52 pcd Exp Locker: pcd $
  2.  */
  3.  
  4. #ifndef __space_h
  5. #define __space_h
  6.  
  7. typedef long          TextPosition;
  8. /*
  9.  * A TextPosition p separates an array of bytes into the
  10.  * bytes before p and the bytes after p. There is no
  11.  * bytes "at p." TextPosition 0 is before all the bytes.
  12.  */
  13.  
  14. typedef int           Coord;
  15. /*
  16.  * Coord are used to measure and place text.
  17.  * Coords < 0 are off the page.
  18.  */
  19.  
  20. typedef double        Inches;
  21. /*
  22.  * Inches are used to measure physical dimensions.
  23.  * The conversion between a Coord and an Inch is
  24.  * determined by the View class.
  25.  */
  26.  
  27. class BRect{
  28.   /* a rectangle in quadrant 1
  29.    */
  30.  
  31. public:
  32.   BRect(Coord ix=0, Coord iy=0, Coord iw=0, Coord ih=0)
  33.     /* USE : assert(ix>=0 && iy >= 0 && iw >= 0 && ih >= 0);
  34.      *       brect = new BRect(ix, iy, iw, ih);
  35.      ******/
  36.     { x = ix; y = iy; width_ = iw; height_ = ih; };
  37.  
  38.   int operator==(const BRect& other)
  39.     { return x == other.x && y == other.y
  40.     && width_ == other.width_ && height_ == other.height_; };
  41.  
  42.   int operator<=(const BRect& other)
  43.     /* USE : if(br1 <= br2) // then br1 is a subset of br2
  44.      ******/
  45.     { return left() >= other.left() && right() <= other.right()
  46.     && top() >= other.top() && bottom() <= other.bottom(); };
  47.   
  48.   Coord height(Coord h)
  49.     /* USE : assert(h>=0);
  50.      *       brect.height(h);
  51.      *       assert(brect.height() == h);
  52.      ******/
  53.     { return height_ = h; };
  54.  
  55.   Coord height() const
  56.     /* USE : assert(brect.height() >= 0);
  57.      ******/
  58.     { return height_; };
  59.  
  60.   Coord width() const
  61.     /* USE: assert(brect.width() >= 0);
  62.      */
  63.     { return width_; };
  64.  
  65.   Coord top() const
  66.     /* USE: assert(brect.top() >= 0 && brect.top()<=brect.bottom());
  67.      */
  68.     { return y; };
  69.  
  70.   Coord inc_top(Coord dy)
  71.     /* USE: assert(dy >= -brect.top());
  72.      *      brect.inc_top(dy);
  73.      */
  74.     { return y+=dy; };
  75.  
  76.   Coord bottom() const
  77.     /* USE: assert(brect.bottom() >= 0 && brect.bottom()>=brect.top());
  78.      */
  79.     { return y+height_; };
  80.  
  81.   Coord left() const
  82.     /* USE: assert(brect.left() >= 0 && brect.left()<=brect.right());
  83.      */
  84.     { return x; };
  85.  
  86.   Coord right() const
  87.     /* USE: assert(brect.right() >= 0 && brect.right()>=brect.left());
  88.      */
  89.     { return x+width_; };
  90.  
  91. protected:
  92.   Coord x, y, width_, height_;
  93. };
  94.  
  95. struct Point{
  96.   Coord x,y;
  97. };
  98.  
  99.  
  100. class Extent{
  101.   /*
  102.    * An Extent is three horizontal and two vertical coordinates:
  103.    *
  104.    *     x0  aka width
  105.    *     x1  aka current_x aka left
  106.    *     x2  aka right
  107.    * 
  108.    *     y0  aka ascent aka top
  109.    *     y1  aka descent aka bottom
  110.    */
  111.  
  112. public:
  113.   Extent(Coord a=0, Coord b=0, Coord c=0, Coord d=-1, Coord e=-1)
  114.     { x0 = a; x1 = b; x2 = c; y0 = d; y1 = e; };
  115.  
  116.   void make_bad()
  117.     { x0 = -1; };
  118.  
  119.   int bad() const
  120.     { return x0 < 0; };
  121.  
  122.   Coord current_x(Coord cx)
  123.     { return x1 = cx; };
  124.   Coord current_x() const
  125.     { return x1; };
  126.   Coord move(Coord dx)
  127.     { return x1 += dx; };
  128.  
  129.   void max_ascent(Coord ma)
  130.     { if (ma > ascent()) y0 = ma; };
  131.   void max_descent(Coord md)
  132.     { if (md > descent()) y1 = md; };
  133.  
  134.   Coord width() const
  135.     { return x0; };
  136.   Coord left() const
  137.     { return x1; };
  138.   Coord right(Coord r)
  139.     { return x2 = r; };
  140.   Coord right() const
  141.     { return x2; };
  142.  
  143.   Coord top() const
  144.     { return y0; };
  145.   Coord bottom() const
  146.     { return y1; };
  147.  
  148.   Coord ascent() const
  149.     { return y0; };
  150.   Coord ascent(Coord a)
  151.     { return y0 = a; };
  152.   Coord descent() const
  153.     { return y1; };
  154.   Coord descent(Coord d)
  155.     { return y1=d; };
  156.  
  157.   Coord height() const
  158.     { return ascent()+descent(); };
  159.  
  160.   Coord x0, x1, x2;
  161.   Coord y0, y1;
  162. };
  163.  
  164. #endif
  165.